<template>
  <div>
    <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="酒店名称" prop="hotalName">
            <el-input v-model="form.hotalName" placeholder="请输入酒店名称" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="酒店代码" prop="hotalNo">
            <el-input v-model="form.hotalNo" placeholder="请输入酒店代码" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="酒店类型" prop="hotalType">
            <el-select v-model="form.hotalType" placeholder="请选择酒店类型">
              <el-option
                v-for="dict in dict.type.hot_hotal_hotal_type"
                :key="dict.value"
                :label="dict.label"
                :value="parseInt(dict.value)"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="是否星级酒店" prop="isStar">
            <el-radio-group v-model="form.isStar">
              <el-radio
                v-for="dict in dict.type.hot_hotal_is_star"
                :key="dict.value"
                :label="dict.value"
              >{{dict.label}}</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">

        <el-col :span="12">
          <el-form-item label="酒店档次" prop="grade">
            <el-select v-model="form.grade" placeholder="请选择酒店档次">
              <el-option
                v-for="dict in dict.type.hot_hotal_grade"
                :key="dict.value"
                :label="dict.label"
                :value="parseInt(dict.value)"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="酒店电话" prop="phone">
            <el-input v-model="form.phone" placeholder="请输入酒店电话" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="国家/省/市/区" prop="city">
            <el-input v-model="form.city" placeholder="请输入国家/省/市/区" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="详细地址" prop="address">
            <el-input v-model="form.address" placeholder="请输入详细地址" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">

        <el-col :span="12">
          <el-form-item label="经度" prop="longitude">
            <el-input v-model="form.longitude" placeholder="请输入经度" />
          </el-form-item>

        </el-col>
        <el-col :span="12">
          <el-form-item label="纬度" prop="latitude">
            <el-input v-model="form.latitude" placeholder="请输入纬度" />
          </el-form-item>
        </el-col>
      </el-row>


      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="营业状态" prop="status">
            <el-select v-model="form.status" placeholder="请选择营业状态">
              <el-option
                v-for="dict in dict.type.hot_hotal_status"
                :key="dict.value"
                :label="dict.label"
                :value="parseInt(dict.value)"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="经营类型" prop="operateType">
            <el-select v-model="form.operateType" placeholder="请选择经营类型">
              <el-option
                v-for="dict in dict.type.hot_hotal_operate_type"
                :key="dict.value"
                :label="dict.label"
                :value="parseInt(dict.value)"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="归属品牌">
            <el-select v-model="form.brandId" placeholder="请选择">
              <el-option
                v-for="item in options"
                :key="item.brandId"
                :label="item.brandName"
                :value="item.brandId">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="归属运营区域" prop="area">
            <el-input v-model="form.area" placeholder="请输入运营区域" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="是否提供餐食" prop="isFood">
            <el-radio-group v-model="form.isFood">
              <el-radio
                v-for="dict in dict.type.hot_hotal_is_food"
                :key="dict.value"
                :label="dict.value"
              >{{dict.label}}</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="联系电话" prop="phonenumber">
            <el-input v-model="form.phonenumber" placeholder="请输入联系电话" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="20">
        <el-col :span="24">
          <el-form-item label="酒店介绍">
            <editor v-model="form.introduce" :min-height="192"/>
          </el-form-item>
        </el-col>
      </el-row>

      <!-- 按钮 -->
      <el-row :gutter="20">
        <el-col :span="24" style="text-align: right;">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script>
import { listBrand1,getBrand } from "@/api/hotal/brand/brand";

import { listHotalList, gethotalById, updateHotal, addHotal } from '@/api/hotal/hotal/hotal'
export default {
  dicts: ['hot_hotal_status', 'hot_hotal_grade', 'hot_hotal_is_star', 'hot_hotal_hotal_type', 'hot_hotal_is_food', 'hot_hotal_operate_type'],
  data() {
    return {
      options: [],
      value: '',
      form: {

      },
      // 表单校验
      rules: {
      },
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        brandName: null,
        special: null,
        content: null,
        status: null,
        logo: null,
      },
      hotalId:""
    };
  },
  created() {
    var hotalId = this.$route.query.hotalId;
    if (hotalId){
      this.hotalId = hotalId
      this.init(hotalId)
      this.getBrandById(hotalId)
      this.getBrandList(this.queryParams)
    }


  },
  methods: {
    init(hotalId) { // 接收 hotalId 参数
      gethotalById(hotalId).then(response => {
        this.form = response.data;
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.hotalId != null) {
            updateHotal(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.$router.back()
            });
          }else {
            addHotal(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    // 取消按钮
    cancel() {
      this.$router.back()
    },
    getBrandList() {
      listBrand1(this.queryParams).then(res =>{
        this.options = res.rows
        console.log('查询参数:',this.options)
      })
    },
    getBrandById(hotalId){
      gethotalById(hotalId).then(response => {
        this.form = response.data;
        if (this.form.brandId){
          getBrand(this.form.brandId).then(response =>{
            this.form.brandName=response.data.brandName
          })
        }

      });
    }
  }
}
</script>
